package com.wash.shoes.domain.mtbusy;

import com.wash.shoes.domain.vo.MtPushMessage;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lijianguo
 * @Date 16/09/2024
 * 工厂
 **/
@Component
public class MtCallbackFactory implements ApplicationContextAware {

    private Map<String, MtCallback> callMap = new HashMap();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //根据接口类型返回相应的所有bean
        Map<String, MtCallback> callbackMapTemp = applicationContext.getBeansOfType(MtCallback.class);
        for (Map.Entry<String, MtCallback> entry : callbackMapTemp.entrySet()) {
            MtCallback mtCallback = entry.getValue();
            callMap.put(mtCallback.getType().getCode(), mtCallback);
        }
    }

    /**
     * @author lijianguo
     * @Date 16/09/2024
     * 调用
     **/
    public Integer call(MtCallbackEnum callbackEnum, MtPushMessage message, String token, String developerId) {
        MtCallback mtCallback = callMap.get(callbackEnum.getCode());
        return mtCallback.processBusy(message, token, developerId);
    }
}
